/**
 * 
 */
package barrier;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author Yoni Seroussi
 * @author Roei Raviv
 *
 * This barrier is using the CyclicBarrier supplyed with java,
 * wrapped to "answer" our Barrier interface.
 */
public class CyclicBarrierImpl implements Barrier {

  CyclicBarrier _barrier;
  
  /**
   * @param numOfThreads 
   * 
   */
  public CyclicBarrierImpl(int numOfThreads) {
    _barrier = new CyclicBarrier(numOfThreads);
  }
  
  /* (non-Javadoc)
   * @see barrier.Barrier#await()
   */
  @Override
  public void await() {
    // TODO Auto-generated method stub
    try {
      _barrier.await();
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (BrokenBarrierException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}
